package com.jiang.smartcommunity.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.jiang.smartcommunity.R;
import com.jiang.smartcommunity.tool.Tool;


public class S4DActivity extends BaseActivity implements View.OnClickListener {

    private EditText et1;
    private EditText et2;
    private EditText et3;
    private EditText et4;
    private EditText et5;
    private EditText et6;
    private EditText et7;
    private TextView textView10;
    private TextView textView13;
    private TextView textView14;
    private TextView textView15;
    private TextView textView16;
    private TextView textView17;
    private TextView textView18;
    private Button button5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_s4_d);
        initView();
        setTitle("个人车辆信息卡");
        if (Tool.carIndex != -1) {
            S4Activity.Car car = Tool.CARS.get(Tool.carIndex);
            et1.setText(car.s1);
            et2.setText(car.s2);
            et3.setText(car.s3);
            et4.setText(car.s4);
            et5.setText(car.s5);
            et6.setText(car.s6);
            et7.setText(car.s7);
        }
    }

    private void initView() {
        et1 = (EditText) findViewById(R.id.et1);
        et2 = (EditText) findViewById(R.id.et2);
        et3 = (EditText) findViewById(R.id.et3);
        et4 = (EditText) findViewById(R.id.et4);
        et5 = (EditText) findViewById(R.id.et5);
        et6 = (EditText) findViewById(R.id.et6);
        et7 = (EditText) findViewById(R.id.et7);
        textView10 = (TextView) findViewById(R.id.textView10);
        textView13 = (TextView) findViewById(R.id.textView13);
        textView14 = (TextView) findViewById(R.id.textView14);
        textView15 = (TextView) findViewById(R.id.textView15);
        textView16 = (TextView) findViewById(R.id.textView16);
        textView17 = (TextView) findViewById(R.id.textView17);
        textView18 = (TextView) findViewById(R.id.textView18);
        button5 = (Button) findViewById(R.id.button5);

        button5.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button5:
                submit();
                break;
        }
    }

    private void submit() {
        // validate
        String et1String = et1.getText().toString().trim();
        if (TextUtils.isEmpty(et1String)) {
            Toast.makeText(this, "车牌号", Toast.LENGTH_SHORT).show();
            return;
        }

        String et2String = et2.getText().toString().trim();
        if (TextUtils.isEmpty(et2String)) {
            Toast.makeText(this, "车位号", Toast.LENGTH_SHORT).show();
            return;
        }

        String et3String = et3.getText().toString().trim();
        if (TextUtils.isEmpty(et3String)) {
            Toast.makeText(this, "停车卡号", Toast.LENGTH_SHORT).show();
            return;
        }

        String et4String = et4.getText().toString().trim();
        if (TextUtils.isEmpty(et4String)) {
            Toast.makeText(this, "车主姓名", Toast.LENGTH_SHORT).show();
            return;
        }

        String et5String = et5.getText().toString().trim();
        if (TextUtils.isEmpty(et5String)) {
            Toast.makeText(this, "车主手机号", Toast.LENGTH_SHORT).show();
            return;
        }

        String et6String = et6.getText().toString().trim();
        if (TextUtils.isEmpty(et6String)) {
            Toast.makeText(this, "相关住户姓名", Toast.LENGTH_SHORT).show();
            return;
        }

        String et7String = et7.getText().toString().trim();
        if (TextUtils.isEmpty(et7String)) {
            Toast.makeText(this, "地址", Toast.LENGTH_SHORT).show();
            return;
        }
        if (Tool.carIndex != -1) {
            S4Activity.Car car = Tool.CARS.get(Tool.carIndex);
            car.s1 = et1String;
            car.s2 = et2String;
            car.s3 = et3String;
            car.s4 = et4String;
            car.s5 = et5String;
            car.s6 = et6String;
            car.s7 = et7String;
        } else {
            Tool.CARS.add(new S4Activity.Car(et1String,et2String,et3String,et4String,et5String,et6String,et7String));
        }

        toast("保存成功");
        finish();


    }
}